//
//  YKPopMenu.m
//  youkan
//
//  Created by mac mini on 16/2/25.
//  Copyright © 2016年 Honsintech. All rights reserved.
//

#import "YKPopMenu.h"

@implementation YKPopMenu

+(instancetype)showInRect:(CGRect)rect{
    YKPopMenu *menu = [[YKPopMenu alloc]initWithFrame:rect];
    menu.userInteractionEnabled = YES;
    menu.image =[UIImage imageWithStretchableName:@"popover_background"];
    [YKKeyWindow addSubview:menu];
    return menu;
}
+(void)hide{
    for (UIView *popMenu in YKKeyWindow.subviews) {
        if ([popMenu isKindOfClass:self]) {
            [popMenu removeFromSuperview];
        }
    }
}
-(void)setContentView:(UIView *)contentView{
    [_contentView removeFromSuperview]; //!> 将contentView重父视图中移除，保证只有一个
    _contentView = contentView;
    contentView.backgroundColor =[UIColor lightGrayColor];
    [self addSubview:contentView];
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat y =9;
    CGFloat margin= 5;
    CGFloat x = margin;
    CGFloat w= self.width -2*margin;
    CGFloat h= self.height-y-margin;
    _contentView.frame = CGRectMake(x, y, w, h );
}
@end
